import {createStore} from "redux";

const defaultState = {
    systemTips: [],
    webSocket: '',
    userName: '',
    userId: '',
    userList: '',
    messageList: []
}

const reducer = (state = defaultState, action) => {
    switch (action.type) {
        case 'tipsPush':
            return {...state, systemTips: [action.data, ...state.systemTips]}
        case 'tipsClear':
            return {...state, systemTips: []}
        case 'socketConnect':
            return {...state, webSocket: action.data}
        case 'setUserName':
            return {...state, userName: action.data}
        case 'setUserId':
            return {...state, userId: action.data}
        case 'setUserList':
            return {...state, userList: action.data}
        case 'pushMessage':
            return {...state, messageList: [...state.messageList, action.data]}
        default:
            return {...state};
    }
}

export default createStore(reducer)